//
//  Emoticon.swift
//  EmoticonKeyBoard
//
//  Created by Arvin on 15/11/20.
//  Copyright © 2015年 Arvin. All rights reserved.
//

import UIKit

class EmoticonPackages: NSObject {
    
    var emoticonsList = [Emoticon]()
    
    // 组名
    var group_name_cn: String?
    // emoji组表情
    var emoticons: [[String: String]]?
    // 表情包名称
    var id: String?
    
    init(id: String, group_name_cn: String?, emoticons: [[String: String]]?) {
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
        self.id = id
        if let dicts = emoticons {
            var index = 0
            for item in dicts {

                let emoticon = Emoticon(id: id, dict: item)
                emoticonsList.append(emoticon)
                index++
                if index == 20 {
                    let emo = Emoticon(delete: true)
                    emoticonsList.append(emo)
                    index = 0
                }
            }
            
        }
        super.init()
        addMoreEmojis()
    }
    
    private func addMoreEmojis() {
        // 不足的格子, 补足
        let totle = emoticonsList.count%21
        if totle == 0 {
            return
        }
        
        for _ in totle..<20 {
            let emoji = Emoticon(empty: true)
            emoticonsList.append(emoji)
        }
        let em = Emoticon(delete: true)
        emoticonsList.append(em)

    }

    override var description: String {
        return ("group_name_cn=\(group_name_cn), id=\(id), emoticons=\(emoticons)")
    }
    
}
